<template>
  <div class="app-container">
    <div id="map"></div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="门店名称" prop="showOrNot">
          <el-select clearable v-model="queryParams.storeName">
            <el-option
              v-for="(item, index) of postione"
              :key="index"
              :label="item.value"
              :value="item.key"
              >{{ item.value }}</el-option
            >
          </el-select>
        </el-form-item> -->
      <el-form-item label="商品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付状态" prop="isPayment">
        <el-select clearable v-model="queryParams.isPayment">
          <el-option
            v-for="(item, index) of postione"
            :key="index"
            :label="item.value"
            :value="item.key"
            >{{ item.value }}</el-option
          >
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['business:ChargebackRule:query']"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['business:ChargebackRule:add']">新增</el-button>
            </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
           v-hasPermi="['orderList:productList:Billing']"
          @click="handlePayment"
          :disabled="!multiple"
          >开单</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:ChargebackRule:del']"
          >批量删除</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="storeList"
      max-height="650px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="产品订单ID" align="center" prop="productOrderId" /> -->
      <el-table-column label="订单号" align="center" prop="productOrderId" />
      <el-table-column label="所属区域" align="center" prop="regionName" />
      <el-table-column label="所属门店" align="center" prop="storeName" />
      <el-table-column label="商品名称" align="center" prop="productName" />
      <el-table-column label="数量" align="center" prop="productNum" />
      <!-- <el-table-column label="附加商品" align="center" prop="productImg">
        <template slot-scope="scope">
          <img :src="scope.row.productImg" style="width: 60px; height: 60px" />
        </template>
      </el-table-column> -->
      <el-table-column label="用户手机号" align="center" prop="userPhonenum" />
      <el-table-column label="用户名称" align="center" prop="userName" />
      
      <el-table-column label="技师名" align="center" prop="technicianName" />
      <!-- <el-table-column label="工号" align="center" prop="technicianCode" /> -->
   
      <el-table-column label="商品价格" align="center" prop="originalPrice">
        <template slot-scope="scope">
          ￥{{ scope.row.originalPrice || "--" }}
        </template>
      </el-table-column>
      <el-table-column label="提成金额" align="center" prop="commissionRate">
        <template slot-scope="scope">
          ￥{{ scope.row.royalty || "--" }}
        </template>
      </el-table-column>

     
      <el-table-column
        prop="isPayment"
        label="支付状态"
        filter-placement="bottom-end"
      >
        <template slot-scope="scope">
          <el-tag
            v-if="scope.row.isPayment == 1"
            type="warning"
            disable-transitions
            >未支付</el-tag
          >
          <el-tag
            v-if="scope.row.isPayment == 2"
            type="success"
            disable-transitions
            >已支付</el-tag
          >
          <el-tag
            v-if="scope.row.isPayment == 3"
            type="danger"
            disable-transitions
            >已退款</el-tag
          >
          <el-tag
            v-if="scope.row.isPayment == 4"
            type="info"
            disable-transitions
            >退款失败</el-tag
          >
          <el-tag v-if="!scope.row.isPayment" type="info" disable-transitions
            >暂无</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="chargebackScale">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.paymentType == 1">微信</el-tag>
          <el-tag v-if="scope.row.paymentType == 2">支付宝</el-tag>
          <el-tag v-if="scope.row.paymentType == 3">现金</el-tag>
          <el-tag v-if="scope.row.paymentType == 4">银行卡</el-tag>
          <el-tag v-if="scope.row.paymentType == 5">店铺储蓄卡</el-tag>
          <el-tag v-if="scope.row.paymentType == 6">其他</el-tag>
          <el-tag v-if="scope.row.paymentType == 7">扫码支付</el-tag>
          <el-tag v-if="scope.row.paymentType == 8">团购券</el-tag>
          <el-tag v-if="!scope.row.paymentType">暂无</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="支付时间"   align="center"  prop="paymentTime" />
      <el-table-column label="支付交易号"   align="center"  prop="productOrderId" />
      
      <el-table-column label="创建人"   align="center"  prop="createBy" />
      <el-table-column label="创建时间"   align="center"  prop="createTime" />
      <el-table-column label="修改人"   align="center"  prop="updateBy" />
      <el-table-column label="修改时间"   align="center"  prop="updateTime" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150"
      >
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-refresh"
            >退单</el-button
          > -->
          <el-button
            v-if="scope.row.isPayment == '1'"
            size="mini"
            type="text"
            icon="el-icon-news"
            v-hasPermi="['orderList:productList:pay']"
            @click="PayRefundClick(scope.row, '支付')"
            >支付</el-button
          >
          <el-button
            v-if="scope.row.isPayment == '2'"
            size="mini"
            type="text"
            icon="el-icon-s-finance"
             v-hasPermi="['orderList:productList:refund']"
            @click="PayRefundClick(scope.row, '退款')"
            >退款</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['orderList:productList:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['orderList:productList:delet']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改门店对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="980px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        v-if="open"
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="退单规则名称"
              prop="chargebackName"
              label-width="170px"
            >
              <el-input
                v-model="form.chargebackName"
                placeholder="请输入退单规则名称"
                style="width: 222px"
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
          <el-form-item label="状态" prop="status">
            <el-select clearable v-model="form.status">
              <el-option
                v-for="(item, index) of List"
                :key="index"
                :label="item.value"
                :value="item.key"
                >{{ item.value }}</el-option
              >
            </el-select>
          </el-form-item>
          </el-col> -->
        </el-row>
        <!-- 退单方式 -->
        <div>
          <!-- <el-row>
              <el-form-item label="退单方式：" label-width="180px">
              </el-form-item>
            </el-row> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="退单方式" label-width="170px">
                <el-radio-group
                  v-model="form.chargebackWay"
                  @change="handleChange"
                >
                  <el-radio :label="1">小程序手动退单</el-radio>
                  <el-radio :label="2">系统自动退单</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <!-- 自动退单 -->
        <div v-if="form.chargebackWay === 2">
          <div>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="服务时间开始后"
                  prop="chargebackTime"
                  label-width="170px"
                >
                  <div style="display: flex; align-items: center; height: 36px">
                    <el-input
                      v-model="form.chargebackTime"
                      placeholder="请输入自动退单时间"
                      style="width: 222px"
                    />
                    <span class="unit">分钟内</span>
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="此处设置服务开始后N分钟内未点击【上钟】按钮系统将自动为客户退单，同时释放技师服务时间"
                      placement="top"
                    >
                      <i class="el-icon-warning" style="color: #f7453e"></i>
                    </el-tooltip>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="11" style="display: flex">
                <el-form-item label="扣款比例" prop="chargebackScale">
                  <div style="display: flex; align-items: center; height: 36px">
                    <el-input
                      v-model="form.chargebackScale"
                      placeholder="请输入退款比例"
                      style="width: 222px"
                    />
                    <span class="unit">%</span>
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="按项目实付金额计算"
                      placement="top"
                    >
                      <i class="el-icon-warning" style="color: #f7453e"></i>
                    </el-tooltip>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <!-- <el-row>
            <el-col :span="12">
              <el-form-item label="归属门店" prop="storeId">
                <el-select
                  clearable
                  v-model="form.storeId"
                  @change="changePostione"
                >
                  <el-option
                    v-for="(item, index) of postione"
                    :key="index"
                    :label="item.value"
                    :value="item.key"
                    >{{ item.value }}</el-option
                  >
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="规则类型" prop="chargebackType">
                <el-select
                  clearable
                  v-model="form.chargebackType"
                  @change="changeType"
                >
                  <el-option
                    v-for="(item, index) of Type"
                    :key="index"
                    :label="item.value"
                    :value="item.key"
                    >{{ item.value }}</el-option
                  >
                </el-select>
              </el-form-item>
            </el-col>
          </el-row> -->

        <div v-if="form.chargebackWay === 1">
          <!-- 项目开始前退单规则 -->
          <div>
            <el-row>
              <el-form-item label="服务时间开始前：" label-width="180px">
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否扣费" label-width="170px">
                  <el-radio-group v-model="form.chargeBeforeType">
                    <el-radio :label="2">是</el-radio>
                    <el-radio :label="1">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <div v-for="item in itemBeforeRuleList" :key="item.id">
              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="服务时间开始前"
                    :prop="'chargeBeforeTime' + item.id"
                    label-width="170px"
                  >
                    <div
                      style="display: flex; align-items: center; height: 36px"
                    >
                      <el-input
                        v-model="form['chargeBeforeTime' + item.id]"
                        placeholder="请输入时间"
                        style="width: 222px"
                      />
                      <span class="unit">分钟内</span>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="10" style="display: flex">
                  <el-form-item
                    label="扣款比例"
                    :prop="'chargeBeforeScale' + item.id"
                  >
                    <div
                      style="display: flex; align-items: center; height: 36px"
                    >
                      <el-input
                        v-model="form['chargeBeforeScale' + item.id]"
                        placeholder="请输入退款比例"
                        style="width: 222px"
                      />
                      <span class="unit">%</span>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="按项目实付金额计算"
                        placement="top"
                      >
                        <i class="el-icon-warning" style="color: #f7453e"></i>
                      </el-tooltip>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="2">
                  <div v-if="form.chargeBeforeType === 2">
                    <i
                      style="
                        cursor: pointer;
                        margin-left: 6px;
                        margin-top: 5px;
                        font-size: 20px;
                      "
                      v-if="itemBeforeRuleList.length > 1"
                      class="el-icon-remove-outline"
                      @click="del(item.id)"
                    ></i>
                    <i
                      style="
                        cursor: pointer;
                        margin-left: 6px;
                        margin-top: 5px;
                        font-size: 20px;
                      "
                      v-if="itemBeforeRuleList.length < 5"
                      class="el-icon-circle-plus-outline"
                      @click="add"
                    ></i>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
          <!-- 项目开始后退单规则 -->
          <div>
            <el-row>
              <el-form-item label="服务时间开始后：" label-width="180px">
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否扣费" label-width="170px">
                  <el-radio-group v-model="form.chargebackType">
                    <el-radio :label="2">是</el-radio>
                    <el-radio :label="1">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <div v-for="item in itemAfterRuleList" :key="item.id">
              <el-row>
                <el-col :span="12">
                  <el-form-item
                    label="服务时间开始后"
                    :prop="'chargebackTime' + item.id"
                    label-width="170px"
                  >
                    <div
                      style="display: flex; align-items: center; height: 36px"
                    >
                      <el-input
                        v-model="form['chargebackTime' + item.id]"
                        placeholder="请输入时间"
                        style="width: 222px"
                      />
                      <span class="unit">分钟内</span>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="10" style="display: flex">
                  <el-form-item
                    label="扣款比例"
                    :prop="'chargebackScale' + item.id"
                  >
                    <div
                      style="display: flex; align-items: center; height: 36px"
                    >
                      <el-input
                        v-model="form['chargebackScale' + item.id]"
                        placeholder="请输入退款比例"
                        style="width: 222px"
                      />
                      <span class="unit">%</span>
                      <el-tooltip
                        class="item"
                        effect="dark"
                        content="按项目实付金额计算"
                        placement="top"
                      >
                        <i class="el-icon-warning" style="color: #f7453e"></i>
                      </el-tooltip>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="2">
                  <div v-if="form.chargebackType === 2">
                    <i
                      style="
                        cursor: pointer;
                        margin-left: 6px;
                        margin-top: 8px;
                        font-size: 20px;
                      "
                      v-if="itemAfterRuleList.length > 1"
                      class="el-icon-remove-outline"
                      @click="delAfter(item.id)"
                    ></i>
                    <i
                      style="
                        cursor: pointer;
                        margin-left: 6px;
                        margin-top: 8px;
                        font-size: 20px;
                      "
                      v-if="itemAfterRuleList.length < 5"
                      class="el-icon-circle-plus-outline"
                      @click="addAfter"
                    ></i>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <el-row>
          <el-col :span="12" style="display: flex">
            <el-form-item
              label="技师提成比例"
              prop="commissionRate"
              label-width="170px"
            >
              <div style="display: flex; align-items: center; height: 36px">
                <el-input
                  v-model="form.commissionRate"
                  placeholder="请输入技师提成比例"
                  style="width: 222px"
                />
                <span class="unit">%</span>
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="退款扣除金额，分%多少给技师"
                  placement="top"
                >
                  <i class="el-icon-warning" style="color: #f7453e"></i>
                </el-tooltip>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="退单说明" prop="status" label-width="170px">
              <el-input
                v-model="form.chargebackExplain"
                placeholder="请输入退单说明"
                style="width: 222px"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 下单弹窗/修改订单 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="orderVisible"
      width="900px"
      append-to-body
      :close-on-click-modal="false"
      @close="orderClose"
    >
      <el-form
        ref="orderFormRef"
        :model="orderForm"
        :rules="orderRules"
        label-width="110px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="归属区域" prop="regionId">
              <el-select
                :disabled="dialogTitle == '修改订单'"
                clearable
                v-model="orderForm.regionId"
                @change="regionChange"
              >
                <el-option
                  v-for="(item, index) of regionOption"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  >{{ item.label }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属门店" prop="storeId">
              <el-select
                :disabled="dialogTitle == '修改订单'"
                clearable
                v-model="orderForm.storeId"
                @change="storeIdChange"
              >
                <el-option
                  v-for="(item, index) of storeOption"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  >{{ item.label }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户电话" prop="phoneNumber">
              <el-input
                :disabled="dialogTitle == '修改订单'"
                v-model="orderForm.phoneNumber"
                placeholder="请输入客户电话"
                style="width: 222px"
                @blur="phoneChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称">
              <el-input
                disabled
                v-model="orderForm.userName"
                style="width: 222px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="余额">
              <el-input
                disabled
                v-model="orderForm.sumMoney"
                style="width: 222px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="附加商品"
              prop="productId"
              placeholder="请选择附加商品"
            >
              <el-select
                :disabled="dialogTitle == '修改订单'"
                clearable
                v-model="orderForm.productId"
                @change="goodsChange"
              >
                <el-option
                  v-for="(item, index) of goodsOption"
                  :key="index"
                  :label="item.label"
                  :value="parseInt(item.value)"
                  >{{ item.label }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                        <el-form-item label="客户名称" prop="userName">
                            <el-input v-model="orderForm.userName" placeholder="请输入客户名称" style="width: 222px" />
                        </el-form-item>
                    </el-col> -->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="附加商品数量"
              prop="productNum"
              placeholder="请选择附加商品"
            >
              <el-input-number
                :disabled="dialogTitle == '修改订单'"
                v-model="orderForm.productNum"
                @change="goodsNumChange"
                :min="1"
                :max="99"
              ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付方式" prop="paymentType">
              <el-select
                :disabled="dialogTitle == '修改订单'"
                clearable
                v-model="orderForm.paymentType"
                @change="paymentTypeChange"
              >
                <el-option
                  v-for="(item, index) of paymentTypes"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  >{{ item.label }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item
              label="附加商品单价"
              prop="price"
              placeholder="附加商品单价"
            >
              <el-input
                v-model="orderForm.price"
                style="width: 222px"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="选择技师"
              prop="technicianId"
              placeholder="请选择技师"
            >
              <el-select
                clearable
                v-model="orderForm.technicianId"
                @change="technicianChange"
              >
                <el-option
                  v-for="(item, index) of technicianList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  >{{ item.label }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" v-if="orderForm.paymentType == 7">
            <el-form-item label="条形码" prop="payCode">
              <el-input
                v-model="orderForm.payCode"
                placeholder="请输入条形码"
                @change="handleScanCode"
                ref="barcode"
                style="width: 222px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价" prop="actuallyMoney">
              <el-input
                v-model="orderForm.actuallyMoney"
                disabled
                placeholder="请输入总价"
                style="width: 222px"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-if="dialogTitle != '修改订单'"
          type="primary"
          @click="clickSubmit"
          >立即支付</el-button
        >
        <el-button
          v-if="dialogTitle != '修改订单'"
          type="primary"
          @click="laterSubmit"
          >稍后支付</el-button
        >
        <el-button v-else @click="editSubmit" type="primary">确 定</el-button>
        <el-button @click="clickCancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 支付/退款 -->
    <el-dialog
      :title="PayRefundTitle"
      :visible.sync="PayRefundVisible"
      append-to-body
      :close-on-click-modal="false"
      @close="PayRefundClose"
    >
      <el-form
        ref="formListRef"
        :model="formList"
        :rules="formListRules"
        label-width="110px"
      >
        <el-form-item label="归属区域">
          <el-select disabled v-model="PayRefundRow.regionId">
            <el-option
              v-for="(item, index) of regionOption"
              :key="index"
              :label="item.label"
              :value="item.value"
              >{{ item.label }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="归属门店">
          <el-select disabled v-model="PayRefundRow.storeId">
            <el-option
              v-for="(item, index) of storeOption"
              :key="index"
              :label="item.label"
              :value="item.value"
              >{{ item.label }}</el-option
            >
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="客户名称">
          {{ PayRefundRow.phoneNumber }}
        </el-form-item> -->

        <el-form-item label="手机号">
          {{ PayRefundRow.userPhonenum }}
        </el-form-item>

        <el-form-item label="商品名称">
          {{ PayRefundRow.productName }}
        </el-form-item>

        <el-form-item label="数量">
          {{ PayRefundRow.productNum }}
        </el-form-item>

        <el-form-item label="技师名称">
          <el-select disabled v-model="PayRefundRow.technicianId">
            <el-option
              v-for="(item, index) of technicianList"
              :key="index"
              :label="item.label"
              :value="item.value"
              >{{ item.label }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="支付金额">
          {{ PayRefundRow.originalPrice }}
        </el-form-item>

        <el-form-item
          label="支付方式"
          prop="paymentType"
          v-if="PayRefundTitle == '支付'"
        >
          <el-select
            clearable
            v-model="formList.paymentType"
            @change="paymentTypeChange1"
            placeholder="请选择支付方式"
          >
            <el-option
              v-for="(item, index) of paymentTypes"
              :key="index"
              :label="item.label"
              :value="item.value"
              >{{ item.label }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item
          label="条形码"
          prop="payCode"
          v-if="formList.paymentType == 7"
        >
          <el-input
            autofocus
            v-model="formList.payCode"
            placeholder="请输入条形码"
            @change="handleScanCode1"
            ref="formListCode"
            style="width: 200px"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="退单金额"
          prop="beChargebackRatio"
          v-if="PayRefundTitle == '退款'"
        >
          <el-input
            v-model="formList.beChargebackRatio"
            placeholder="请输入退单金额"
            style="width: 200px"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handlePayRefund" type="primary">确 定</el-button>
        <el-button @click="PayRefundClose">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  fetchRegionList,
  fetchStoreList,
  fetchGoodsList,
} from "@/api/system/orderList/order";
import {
  getProductList,
  immediatePayment,
  laterPayment,
  getTechnicians,
  deleteProduct,
  productRefundt,
  updateEarningsByOrderId,
  product,
} from "@/api/system/orderList/productList";

import { userCardList } from "@/api/system/card/storeCard";

export default {
  name: "productList",
  data() {
    return {
      map: null,
      local: null,
      mk: null,
      latitude: "",
      longitude: "",
      keyWords: "",
      result: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门店表格数据
      storeList: [],
      //技师列表
      technicianList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      orderForm: {
        regionId: "",
        storeId: "",
        phoneNumber: "",
        productId: "",
        productNum: 1,
        paymentTypes: "",
        price: "",
        technicianId: "",
        payCode: "",
        userName: "",
        sumMoney: "",
      },
      formList: {
        beChargebackRatio: null,
        paymentType: null,
        payCode: null,
      },
      formListRules: {
        beChargebackRatio: [
          { required: true, message: "请输入退单比例", trigger: "blur" },
        ],
        paymentType: [
          { required: true, message: "请选择支付方式", trigger: "blur" },
        ],
        payCode: [{ required: true, message: "请输入条形码", trigger: "blur" }],
      },
      orderRules: {
        regionId: [
          { required: true, message: "请选择归属区域", trigger: "blur" },
        ],
        storeId: [
          { required: true, message: "请选择归属门店", trigger: "blur" },
        ],
        phoneNumber: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "请输入有效的手机号",
            trigger: "change",
          },
        ],
        productId: [
          { required: true, message: "请选择附加商品", trigger: "blur" },
        ],
        productNum: [
          { required: true, message: "请选择附加商品数量", trigger: "blur" },
        ],
        paymentType: [
          { required: true, message: "请选择支付方式", trigger: "blur" },
        ],
        price: [
          { required: true, message: "请输入附加商品单价", trigger: "blur" },
        ],
        technicianId: [
          { required: true, message: "请选择技师", trigger: "blur" },
        ],
        payCode: [{ required: true, message: "请输入条形码", trigger: "blur" }],
      },
      // 表单参数
      form: {
        chargebackWay: 1,
        chargeBeforeType: 2,
        chargeBeforeTime: "",
        chargeBackScale: "",
        chargebackType: 2,
        chargebackTime: "",
        chargebackScale: "",
      },
      itemBeforeRuleNumber: 0,
      itemBeforeRuleList: [{ id: 0 }],
      itemAfterRuleNumber: 0,
      itemAfterRuleList: [{ id: 0 }],
      pageNumber: 0,
      // 表单校验
      rules: {
        commissionRate: [
          { required: true, message: "请输入技师提成比例", trigger: "blur" },
          {
            pattern: /^(?:[1-9]\d?|100)$/,
            message: "请输入正确提成比例",
            trigger: "blur",
          },
        ],
        chargebackTime: [
          { required: true, message: "请输入分钟", trigger: "blur" },
          {
            pattern: /^(?:[1-9]\d?|100)$/,
            message: "请输入正确数据",
            trigger: "blur",
          },
        ],
        chargebackScale: [
          { required: true, message: "请输入退款比例", trigger: "blur" },
          {
            pattern: /^(?:[1-9]\d?|100)$/,
            message: "请输入正确数据",
            trigger: "blur",
          },
        ],
      },
      options: [],
      List: [
        {
          key: 1,
          value: "启用",
        },
        {
          key: 2,
          value: "不启用",
        },
      ],
      Type: [
        {
          key: 1,
          value: "不扣费",
        },
        {
          key: 2,
          value: "扣费",
        },
      ],
      region: [],
      postione: [
        {
          key: 1,
          value: "未支付",
        },
        {
          key: 2,
          value: "已支付",
        },
        {
          key: 3,
          value: "已退款",
        },
        {
          key: 4,
          value: "退款失败",
        },
      ],
      orderVisible: false,
      dialogTitle: "开单",
      PayRefundVisible: false, //支付退款
      PayRefundTitle: "", //支付退款
      PayRefundRow: {}, //支付退款数据
      storeId: "",
      regionId: "",
      payCode: "",
      goodsOption: [], //商品下拉框
      regionOption: [], // 区域下拉框
      storeOption: [], // 门店下拉框
      paymentTypes: [
        {
          value: 5,
          label: "店铺储蓄卡",
        },
        {
          value: 7,
          label: "扫码支付",
        },
        {
          value: 3,
          label: "现金支付",
        },
        {
          value: 6,
          label: "其他",
        },
      ],
      editParams: {},
    };
  },
  created() {
    this.getList();
    this.getRegionOption();
  },
  methods: {
    //取消事件
    handleCancle(row) {
      console.log("row", row);
      row.visible = false;
    },
    //获取技师列表
    async getTechnician(data) {
      let obj = {
        belongStoreId: data.belongStoreId,
        state: "1",
        onTheJob: "1",
      };
      const res = await getTechnicians(obj);
      if (res.code == 200) {
        this.technicianList = res.rows.map((item) => {
          item.value = item.id;
          item.label = item.name;
          item.jobNumber = item.jobNumber;
          return item;
        });
      }
    },

    getCardList() {
      let obj = {
        phoneNumber: this.orderForm.phoneNumber,
        storeId: this.orderForm.storeId,
        regionId: this.orderForm.regionId,
      };
      userCardList(obj).then((res) => {
        if (res.data) {
          this.orderForm.userName = res.data.userName;
          this.orderForm.sumMoney = res.data.valueMoney;
          console.log(res.data, "userName");
          console.log(this.orderForm, " this.orderForm");
          this.$forceUpdate();
        }
      });
    },
    //切换技师
    technicianChange(e) {
      const aa = this.technicianList.find((item) => item.value == e);
      this.editParams.technicianId = e;
      this.editParams.name = aa.name;
      this.editParams.jobNumber = aa.jobNumber;
      console.log(e, aa);
    },
    //支付退款
    handlePayRefund() {
      // console.log("11111", this.PayRefundRow);

      this.$refs["formListRef"].validate((valid) => {
        if (!valid) return this.$message.error("请将表单数据填写完整");
        if (this.PayRefundTitle == "支付") {
          this.handletoPay(this.PayRefundRow);
        } else {
          this.handletoRefund(this.PayRefundRow);
        }
      });
    },
    //补单支付
    handletoPay(row) {
      row.phoneNumber = row.userPhonenum;
      const params = {
        regionId: Number(row.regionId),
        regionName: row.regionName,
        storeId: Number(row.storeId),
        storeName: row.storeName,
        technicianId: row.technicianId,
        paymentType: this.formList.paymentType,
        productId: row.productId,
        userPhonenum: row.phoneNumber,
        productNum: row.productNum,
        payCode: this.formList.payCode,
        id: row.id,
        productName: row.productName,
      };
      immediatePayment(params).then((res) => {
        if (res.code !== 200) {
          this.$nextTick(() => {
            //给扫码枪聚焦
            this.$refs.formListCode.focus();
          });
          return;
        }
        this.PayRefundClose();
        this.getList();
      });
    },
    handletoRefund(row) {
      console.log("row", row);
      productRefundt({
        id: row.id,
        beChargebackRatio: this.formList.beChargebackRatio,
      }).then((res) => {
        if (res.code == 200) {
          this.$message.success("退款成功");
          this.PayRefundClose();
          this.getList();
        }
      });
    },
    //附加商品数量改变
    goodsNumChange(e) {
      console.log(e, 1111);
      this.orderForm.productNum = e;
      this.orderForm.actuallyMoney =
        Number(this.orderForm.price) * Number(this.orderForm.productNum);
    },
    paymentTypeChange(e) {
      console.log(e);
      if (e == 7) {
        this.$nextTick(() => {
          //给扫码枪聚焦
          this.$refs.barcode.focus();
        });
      }
    },
    //监听扫码枪
    handleScanCode(event) {
      console.log("回车事件--->", event);
      this.$modal.msgSuccess("扫码成功，请点击立即支付");
      this.orderForm.payCode = event;
    },
    //稍后支付
    laterSubmit() {
      this.$refs["orderFormRef"].validate((valid) => {
        if (!valid) return this.$message.error("请将表单数据填写完整");
        const params = {
          regionId: this.regionId,
          regionName: this.regionName,
          storeId: this.storeId,
          storeName: this.storeName,
          technicianId: this.orderForm.technicianId,
          paymentType: this.orderForm.paymentType,
          productId: this.orderForm.productId,
          userPhonenum: this.orderForm.phoneNumber,
          productNum: this.orderForm.productNum,
          payCode: this.orderForm.payCode,
          actuallyMoney: this.orderForm.actuallyMoney,
        };
        console.log(params);
        laterPayment(params).then((res) => {
          console.log(res);
          if (res.code !== 200) return;
          this.orderForm = {};
          this.$refs["orderFormRef"].resetFields();
          this.orderForm.productNum = 1;
          this.orderVisible = false;
          this.getList();
        });
      });
    },
    // 立即支付
    clickSubmit() {
      this.$refs["orderFormRef"].validate((valid) => {
        if (!valid) return this.$message.error("请将表单数据填写完整");
        const params = {
          regionId: this.regionId,
          regionName: this.regionName,
          storeId: this.storeId,
          storeName: this.storeName,
          technicianId: this.orderForm.technicianId,
          paymentType: this.orderForm.paymentType,
          payCode: this.payCode,
          productId: this.orderForm.productId,
          userPhonenum: this.orderForm.phoneNumber,
          productNum: this.orderForm.productNum,
          payCode: this.orderForm.payCode,
          actuallyMoney: this.orderForm.actuallyMoney,
        };
        console.log(params);
        immediatePayment(params).then((res) => {
          console.log(res);
          this.payCode = "";
          if (res.code !== 200) {
            this.$nextTick(() => {
              //给扫码枪聚焦
              this.$refs.code.focus();
            });
            return;
          }
          this.orderForm = {};
          this.$refs["orderFormRef"].resetFields();
          this.orderVisible = false;
          this.getList();
          this.reset();
        });
      });
    },
    clickCancel() {
      this.orderVisible = false;
      this.$refs["orderFormRef"].resetFields();
      this.reset();
    },
    orderClose() {
      this.orderVisible = false;
      this.$refs["orderFormRef"].resetFields();
      this.reset();
    },
    PayRefundClose() {
      this.PayRefundVisible = false;
      this.$refs["formListRef"].resetFields();
      this.PayRefundRest();
    },
    reset() {
      this.orderForm = {
        regionId: "",
        storeId: "",
        phoneNumber: "",
        productId: "",
        productNum: 1,
        paymentTypes: "",
        price: "",
        technicianId: "",
        payCode: "",
      };
    },
    // 获取归属区域下拉数据
    getRegionOption() {
      fetchRegionList().then((res) => {
        this.regionOption = [
          // {
          //   value: 0
          //    label: "",
          // },
        ];
        this.regionOption.push(
          ...res.data.map((rItem) => {
            return {
              value: rItem.id,
              label: rItem.regionName,
            };
          })
        );
      });
    },
    // 商品切换
    goodsChange(value) {
      this.chooseGoods = this.goodsOption.find((item) => item.value === value);
      // this.orderForm.price = this.goodsOption.find(
      //   (item) => item.value === value
      // ).originalPrice;

      this.goodsOption.forEach((element) => {
        if (value == element.id) {
          this.orderForm.price = element.originalPrice;
          this.orderForm.actuallyMoney =
            Number(this.orderForm.price) *
            Number(this.orderForm.productNum || 1);
        }
      });
    },
    // 归属区域切换
    regionChange(value) {
      console.log(value);
      const selectedOption = this.regionOption.find(
        (item) => item.value === value
      );
      this.regionId = value;
      if (selectedOption) {
        this.regionName = selectedOption.label;
      }
      fetchStoreList({ regionId: value }).then((res) => {
        this.storeOption = [
          // {
          //   value: 0,
          //   label: "",
          // },
        ];
        this.storeOption.push(
          ...res.data.map((rItem) => {
            return {
              label: rItem.storeName,
              value: rItem.id,
            };
          })
        );
      });
      if (this.storeId) {
        this.getGoodsList();
      }
    },
    // 归属门店切换
    storeIdChange(value) {
      console.log(value);
      const selectedOption = this.storeOption.find(
        (item) => item.value === value
      );
      const data = {
        belongStoreId: value,
      };
      this.storeId = value;
      this.storeName = selectedOption.label;
      if (this.regionId) {
        this.getGoodsList();
        this.getTechnician(data);
      }
      if (this.orderForm.phoneNumber) {
        this.getCardList();
      }
    },
    // 获取附加商品列表
    getGoodsList() {
      const params = {
        storeId: this.storeId,
      };
      fetchGoodsList(params).then((res) => {
        if (res.code !== 200) return;
        this.goodsOption = res.data.map((rItem) => {
          return {
            ...rItem,
            label: rItem.productName,
            value: rItem.id,
          };
        });
        if (this.productId) {
          this.goodsChange(this.productId);
        }
      });
    },
    //获取手机号
    phoneChange() {
      if (!(this.regionId && this.storeId))
        return this.$message.error("请先选择归属区域和门店");
      if (this.orderForm.phoneNumber) {
        const params = {
          phoneNumber: this.orderForm.phoneNumber,
          regionId: this.regionId,
          storeId: this.storeId,
        };
        // fetchCustomInfo(params).then((res) => {
        //     this.orderForm = {
        //         ...this.orderForm,
        //         userName: res.data.userName,
        //         valueMoney: res.data.valueMoney,
        //         memberFlag: res.data.memberFlag ? '1' : '2',
        //         valueFlag: res.data.valueFlag ? '1' : '2'
        //     }
        // })
      }
      this.getCardList();
    },
    handlePayment() {
      this.orderForm = {
        productNum: 1,
      };
      this.dialogTitle = "开单";
      this.orderVisible = true;
    },
    getTimeRules(dataList, name) {
      this[dataList] &&
        this[dataList].forEach((item, index) => {
          this.rules = {
            ...this.rules,
            [`charge${name}Time${item.id}`]: [
              { required: true, message: "请输入分钟", trigger: "blur" },
              {
                pattern: /^(?:[1-9]\d?|100)$/,
                message: "请输入正确数据",
                trigger: "blur",
              },
            ],
            [`charge${name}Scale${item.id}`]: [
              { required: true, message: "请输入退款比例", trigger: "blur" },
              {
                pattern: /^(?:[1-9]\d?|100)$/,
                message: "请输入正确退款金额",
                trigger: "blur",
              },
            ],
          };
        });
    },
    changePostione(value) {
      const selectedOption = this.postione.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.storeName = selectedValue;
    },
    changeType(value) {
      const selectedOption = this.postione.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.storeName = selectedValue;
    },
    /** 查询商品列表 */
    getList() {
      console.log(this.queryParams);
      this.loading = true;
      getProductList(this.queryParams).then((response) => {
        this.storeList = response.rows;
        this.storeList.map((item, index) => {
          item.visible = false;
          item.PayIndex = "Code" + index;
          if (item.chargebackWay === 1) {
            item.chargebackWay = "手动退单";
          } else {
            item.chargebackWay = "自动退单";
          }
        });
        console.log("this.storeList", this.storeList);
        this.total = response.total;
        this.loading = false;
      });
    },
    //添加项目开始前退单
    add() {
      this.itemBeforeRuleNumber += 1;
      this.itemBeforeRuleList.push({ id: this.itemBeforeRuleNumber });
      this.getTimeRules("itemBeforeRuleList", "Before");
    },
    //删除项目开始前退单
    del(id) {
      this.itemBeforeRuleList = this.itemBeforeRuleList.filter(
        (item) => item.id != id
      );
      console.log(id, this.itemBeforeRuleList, "55555");
    },
    //添加项目开始后退单
    addAfter() {
      this.itemAfterRuleNumber += 1;
      this.itemAfterRuleList.push({ id: this.itemAfterRuleNumber });
      this.getTimeRules("itemAfterRuleList", "back");
    },
    //删除项目开始前退单
    delAfter(id) {
      console.log(id, "8888888888");
      this.itemAfterRuleList = this.itemAfterRuleList.filter(
        (item) => item.id != id
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        chargebackName: null,
        chargebackWay: 1,
        chargebackTime: null,
        chargebackScale: null,
        chargeBeforeType: 2,
        chargebackType: 2,
        commissionRate: null,
        chargebackExplain: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryForm = {
        pageNum: 1,
        pageSize: 10,
      };
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加规则";
    },
    // 上下架
    handleGround(row, status) {
      const params = {
        id: row.id,
        storeId: row.storeId,
        status: status,
      };
      this.$confirm(
        `此操作将${status === 1 ? "启用" : "禁用"}该数据, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          editStatus(params).then((res) => {
            this.$message({
              type: "success",
              message: `${status === 1 ? "启用" : "禁用"}成功!`,
            });
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消禁用",
          });
        });
    },
    //切换退单方式
    handleChange(val) {
      if (val === 2) {
        this.itemBeforeRuleNumber = 0;
        this.itemAfterRuleNumber = 0;
        this.itemBeforeRuleList = [
          {
            id: this.itemBeforeRuleNumber,
          },
        ];
        this.itemAfterRuleList = [
          {
            id: this.itemAfterRuleNumber,
          },
        ];
        this.form = {
          ...this.form,
          chargebackTime: "",
          chargebackScale: "",
          chargeBeforeType: 2,
          chargebackType: 2,
        };
      } else {
        this.form = {
          ...this.form,
          chargebackTime: "",
          chargebackScale: "",
          chargeBeforeType: 2,
          chargebackType: 2,
        };
      }
    },
    //支付退款
    PayRefundClick(row, type) {
      console.log("row", row);
      this.PayRefundRow = row;
      this.PayRefundVisible = true;
      this.PayRefundTitle = type;
      this.formList = row;
      this.PayRefundRest();
    },
    PayRefundRest() {
      this.formList = {
        beChargebackRatio: "",
        paymentType: "",
        payCode: "",
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // product(row.id).then((res) => {
      //   if (res.code == 200) {
      //     this.orderForm = res.data;
      const data = {
        belongStoreId: Number(row.storeId),
      };
      this.getTechnician(data);
      this.editParams.id = row.id;
      this.editParams.technicianId = row.technicianId;
      //     this.storeId = res.data.storeId;
      //     this.regionId = res.data.regionId;
      //     this.productId = res.data.productId;
      //     this.regionChange(Number(this.regionId));
      //     this.getTechnician(data);
      //     this.dialogTitle = "修改订单";
      //     this.orderVisible = true;
      //   }
      // });
      // return;
      row.paymentType = `${row.paymentType || ""}`;
      row.regionId = Number(row.regionId);
      row.storeId = Number(row.storeId);
      row.phoneNumber = row.userPhonenum;
      // this.orderForm = row
      this.orderForm = {
        regionId: row.regionId,
        storeId: row.storeId,
        phoneNumber: row.phoneNumber,
        productId: row.productId,
        productNum: row.productNum,
        paymentTypes: row.paymentTypes,
        price: row.price,
        technicianId: row.technicianId,
        payCode: row.payCode,
      };
      this.storeId = row.storeId;
      this.regionId = row.regionId;
      this.productId = row.productId;
      this.regionChange(Number(this.regionId));
      this.getCardList();

      this.dialogTitle = "修改订单";
      this.orderVisible = true;

      // getchargeback(id).then((response) => {
      //     const result = response.data
      //     let timeForm = {}
      //     if (result.chargebackWay === 1) {
      //         this.itemBeforeRuleList = result.itemBeforeRule.itemBeforeRuleList.map((item, index) => {
      //             timeForm = {
      //                 ...timeForm,
      //                 ['chargeBeforeTime' + index]: item.chargebackTime,
      //                 ['chargeBeforeScale' + index]: item.chargebackScale
      //             }
      //             return {
      //                 id: index
      //             }
      //         })
      //         timeForm.chargeBeforeType = result.itemBeforeRule.chargebackType
      //         this.itemBeforeRuleNumber = result.itemBeforeRule.itemBeforeRuleList.length - 1
      //         this.itemAfterRuleList = result.itemAfterRule.itemAfterRuleList && result.itemAfterRule.itemAfterRuleList.map((item, index) => {
      //             timeForm = {
      //                 ...timeForm,
      //                 ['chargebackTime' + index]: item.chargebackTime,
      //                 ['chargebackScale' + index]: item.chargebackScale
      //             }
      //             return {
      //                 id: index
      //             }
      //         })
      //         timeForm.chargebackType = result.itemAfterRule.chargebackType
      //         this.itemAfterRuleNumber = result.itemAfterRule.itemAfterRuleList && result.itemAfterRule.itemAfterRuleList.length - 1
      //     }
      //     this.form = {
      //         ...result,
      //         ...timeForm,
      //     }
      //     this.getTimeRules('itemBeforeRuleList', 'Before')
      //     this.getTimeRules('itemAfterRuleList', 'After')
      //     this.open = true
      //     this.title = "修改规则";
      // })
    },
    getTimeList(name, listName) {
      let itemRuleList = [];
      this[`item${listName}RuleList`].forEach((item) => {
        itemRuleList.push({
          chargebackTime: this.form[`charge${name}Time` + item.id],
          chargebackScale: this.form[`charge${name}Scale` + item.id],
        });
      });
      // for(let key in this.form){
      //   if(key.includes(`charge${name}Time`)) {
      //     itemRuleList.push(
      //       {
      //         chargebackTime: this.form[key],
      //         chargebackScale: this.form[`charge${name}Scale` + key.split(`charge${name}Time`)[1]]
      //       }
      //     )
      //   }
      // }
      return {
        chargebackType: this.form[`charge${name}Type`],
        [`item${listName}RuleList`]: itemRuleList,
      };
    },
    //修改提交
    editSubmit() {
      if (this.editParams.technicianId) {
        const aa = this.technicianList.find(
          (item) => item.value == this.editParams.technicianId
        );
        this.editParams.name = aa.name;
        this.editParams.jobNumber = aa.jobNumber;
      }
      const params = {
        technicianId: this.editParams.technicianId,
        name: this.editParams.name,
        jobNumber: this.editParams.jobNumber,
        orderId: this.editParams.id,
      };
      updateEarningsByOrderId(params).then((res) => {
        console.log(res);
        if (res.code !== 200) return;
        this.orderVisible = false;
        this.$message.success("修改成功");
        this.getList();
      });
    },

    /** 提交按钮 */
    submitForm() {
      const itemBeforeRule = this.getTimeList("Before", "Before");
      const itemAfterRule = this.getTimeList("back", "After");
      let params = {
        chargebackName: this.form.chargebackName,
        chargebackWay: this.form.chargebackWay,
        commissionRate: this.form.commissionRate,
        chargebackExplain: this.form.chargebackExplain,
        id: this.form.id || null,
      };
      if (this.form.chargebackWay === 2) {
        params = {
          ...params,
          chargebackTime: this.form.chargebackTime,
          chargebackScale: this.form.chargebackScale,
        };
      } else {
        params = {
          ...params,
          itemBeforeRule,
          itemAfterRule,
        };
      }

      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatechargeback(params).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addchargeback(params).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handReset(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认重置门店编号为"' + ids + '"的数据项？')
        .then(function () {
          return listResetPwd({ userId: ids });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("重置成功");
        })
        .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm('是否确认删除商品名称为"' + row.productName + '"的数据项？')
        .then(function () {
          return deleteProduct(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/store/export",
        {
          ...this.queryParams,
        },
        `store_${new Date().getTime()}.xlsx`
      );
    },
    //列表支付下拉 监听扫码枪
    handleScanCode1(event) {
      console.log("回车事件--->", event);
      this.$modal.msgSuccess("扫码成功，请点击确认收款");
      this.formList.payCode = event;
    },
    paymentTypeChange1(e, PayIndex) {
      if (e == 7) {
        this.$nextTick(() => {
          this.$refs.formListCode.focus();
        });
      }
    },
  },
};
</script>
<style>
.dialog-footer {
  text-align: center;
}

.unit {
  margin-left: 5px;
}
</style>
